using System.Text;
using TestCases.CompareAssert.Core.Interfaces;
using TestCases.Utils;

namespace TestCases.CompareAssert.Core
{
    public class PathBuilder : IPathBuilder
    {
        private readonly IPathBuilder _basePath;
        private readonly StringBuilder _path = new StringBuilder();

        public PathBuilder(string rootName)
        {
            _path.Append(rootName);
        }

        public PathBuilder(IPathBuilder basePath)
        {
            _basePath = basePath;
        }

        public IPathBuilder Indexes(params object[] indexes)
        {
            _path.Append('[').Append(indexes.ToValuesString()).Append(']');
            return this;
        }

        public IPathBuilder Method(string name, params object[] parameters)
        {
            _path.Append('.').Append(name).Append('(').Append(parameters.ToValuesString()).Append(')');
            return this;
        }

        public IPathBuilder Entity(string name)
        {
            _path.Append('.').Append(name);
            return this;
        }

        public string Path
        {
            get { return (_basePath != null) ? _basePath.Path + _path : _path.ToString(); }
        }
    }
}